package artid.com.arttogoa;

import artid.com.arttogoa.R;

import artid.com.arttogoa.barcode.Cache;
import artid.com.arttogoa.parser.ConsultationInfo;
import artid.com.arttogoa.util.AppUtil;
import artid.com.arttogoa.volley.BitmapCache;
import artid.com.arttogoa.volley.VolleyBasic;
import artid.com.arttogoa.volley.VolleyCallback;
import artid.com.arttogoa.volley.VolleyData;
import artid.com.arttogoa.volley.VolleyMap;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageLoader.ImageListener;
import com.android.volley.toolbox.Volley;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * 
 * 项目名称：ArtworkArtA 类名称：ArtConsultationDetailActivity 类描述：资讯详情页面 创建人：耿卫斌
 * 创建时间：2016年5月16日 下午1:21:27
 *
 */
public class ArtConsultationDetailActivity extends BaseActivity implements
		OnClickListener {
	private ImageView mImage_item_zx,share;
	private TextView mText_zx_sh;
	private TextView mText_zx_date;
	private TextView mText_zx_name,mTextDes;
	private TextView mEdit_btn;
	private TextView mtextType,mtextNopass;
	private ImageView mImageShare;
	View zx_det_nopass;
	private ImageLoader mImageLoader;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activituy_zx_det);
		setContent(this, getIntent());
		mContext = ArtConsultationDetailActivity.this;
		RequestQueue mQueue = Volley.newRequestQueue(mContext);
		mImageLoader = new ImageLoader(mQueue, new BitmapCache());
		mTittle = (TextView) findViewById(R.id.title_text);
		mTittle.setText("资讯详情页");
		share = (ImageView)findViewById(R.id.imageShare);
		setBack();
		mReleaseIcon = (ImageView) findViewById(R.id.imageShare);
		mReleaseIcon.setVisibility(View.VISIBLE);
		mReleaseIcon.setOnClickListener(this);
		mImage_item_zx = (ImageView) findViewById(R.id.image_item_zx);
		mText_zx_sh = (TextView) findViewById(R.id.text_zx_sh);
		mText_zx_date = (TextView) findViewById(R.id.text_zx_date);
		mText_zx_name = (TextView) findViewById(R.id.text_zx_name);
		mEdit_btn = (TextView) findViewById(R.id.edit_btn);
		mEdit_btn.setOnClickListener(this);
		zx_det_nopass = (View) findViewById(R.id.zx_det_nopass);
		mtextType = (TextView) findViewById(R.id.textView1);
		mtextNopass = (TextView)findViewById(R.id.text_zx_nopass);
		mTextDes = (TextView)findViewById(R.id.text_zx_det_des);
		reqData(getIntent().getExtras().getString("id"));
	}
	ConsultationInfo itemCons;
	void reqData(String id) {
		VolleyBasic.getInstance(ArtConsultationDetailActivity.this).post(
				Cache.consultationInfo,
				VolleyMap.getInstance().consultationInfo(id),
				ConsultationInfo.class, new VolleyCallback() {
					@Override
					public void onSuccess(VolleyData vd) {
						// TODO Auto-generated method stub
						final ConsultationInfo itemConsultationInfo = (ConsultationInfo) vd
								.getData();
						if (itemConsultationInfo.getState().equals("1")) {
							mText_zx_sh.setText("审核中");
						} else if (itemConsultationInfo.getState().equals("2")) {
							mText_zx_sh.setText("通过审核");
						} else if (itemConsultationInfo.getState().equals("3")) {
							mText_zx_sh.setText("未通过审核");
						}
						mtextType.setText(itemConsultationInfo.getType());

						mText_zx_name.setText(itemConsultationInfo.getAuthor());
						mText_zx_date.setText(itemConsultationInfo.getCreate_time());
						ImageListener listener = ImageLoader.getImageListener(
								mImage_item_zx, R.drawable.yspba_img_mor,
								android.R.drawable.ic_delete);
						mImageLoader.get(itemConsultationInfo.getImgurl()+AppUtil.picWidthUrl, listener);
						if (itemConsultationInfo.getState().equals("3")) {
							itemCons = itemConsultationInfo;
							zx_det_nopass.setVisibility(View.VISIBLE);
							mtextNopass.setText(itemConsultationInfo.getReason());
						}
						mTextDes.setText(itemConsultationInfo.getContent());
						share.setOnClickListener(new OnClickListener() {
							
							@Override
							public void onClick(View arg0) {
								// TODO Auto-generated method stub
								AppUtil.showShare(ArtConsultationDetailActivity.this, 
										itemConsultationInfo.getAuthor(), itemConsultationInfo.getDescription(),
										itemConsultationInfo.getImgurl(), itemConsultationInfo.getSharelink());
							}
						});
					}

					@Override
					public void onError(VolleyError volleyError) {
						// TODO Auto-generated method stub

					}
				});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.title_back:
			finish();
			break;
		case R.id.edit_btn:
			Intent intent = new Intent(ArtConsultationDetailActivity.this,ReleaseConsultationActivity.class);
			Bundle bundle = new Bundle();
			bundle.putSerializable("item", itemCons);
			intent.putExtras(bundle);
			startActivity(intent);
			// finish();
			break;

		default:
			break;
		}

	}

}
